package org.example.order.controller;


import org.example.order.mapper.OrderMapper;
import org.example.order.model.Order;
import org.example.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
@RefreshScope
public class OrderController {

    @Value("${test:111}")
    private String test;

    @Autowired
    private OrderService orderService;

    @GetMapping("add")
    public String add() {
        Order entity = new Order();
        entity.setId("123123");
        entity.setName("test");
        orderService.saveOrUpdate(entity);
        return "add:" + entity.getId();
    }

    @GetMapping("{id}")
    public Order get(@PathVariable String id) {
        return orderService.getById(id);
    }
}
